#include "timestamp.h"
#include <stdio.h>
#include <time.h>
#include <string.h>

int getTimestamp(char* buffer, int bufSize)
{
        // TIMESTAMP & Level
    struct timespec		tm;
    struct tm           t;
    int                 timestamp_l;

    clock_gettime(CLOCK_REALTIME, &tm);

    // localtime_r(&tm.tv_sec, &t);
    gmtime_r(&tm.tv_sec, &t);

    timestamp_l = snprintf(buffer, bufSize, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 
                    t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, tm.tv_nsec / 1000000);

    return timestamp_l;
}
